<template>
  <table>
    <tr>
      <td>资源名称</td>
      <td>资源价格</td>
      <td>操作</td>
    </tr>
    <tr v-for="(item, index) in collect_list" :key="index">
      <td>{{ item.name }}</td>
      <td>{{ item.price }}</td>
      <td>
        <van-button type="default" @click="del_collect(item.id)"
          >取消收藏</van-button
        >
      </td>
    </tr>
  </table>
</template>

<script>
export default {
  data() {
    return {
      collect_list: "",
      user_id:localStorage.getItem('id')
    };
  },
  mounted() {
    this.collect_show();
  },
  methods: {
    collect_show: function () {
      this.myaxios(this.host + "study/collects/", "get", {
        user_id: this.user_id,
      }).then((data) => {
        if (data.code == 200) {
          this.$toast.success(data.msg);
          this.collect_list = data.data;
        } else {
          this.$toast.fail(data.msg);
        }
      });
    },
    del_collect: function (id) {
      this.myaxios(this.host + "study/collect/" + id + "/", "delete",{
        user_id:this.user_id
      }).then(
        (data) => {
          if (data.code == 200) {
            this.$toast.success(data.msg);
            this.collect_show();
          } else {
            this.$toast.fail(data.msg);
          }
        }
      );
    },
  },
};
</script>

<style>
</style>